package com.example.oj.rabbitmq;

import cn.hutool.json.JSONUtil;
import com.example.oj.service.JudgeService;
import com.example.oj.service.SubmitService;
import com.example.ojcommon.common.ExecuteCodeResponse;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RabbitMQListener {
  @Resource
  private JudgeService judgeService;

  @Resource
  private SubmitService submitService;

  @RabbitListener(queues = {"returnResQueue"})
  @RabbitHandler
  public void listenReturnResQueue(ExecuteCodeResponse executeCodeResponse) {
    judgeService.doJudge(executeCodeResponse);
  }

  @RabbitListener(queues = {"updateQueue"})
  @RabbitHandler
  public void listenUpdateQueue(Long submitId) {
    submitService.updateStateById(submitId);
  }

}
